import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

/**
 * @author Egor Kulikov (egor@egork.net)
 */
public class MTotalF {
	@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
	private InputReader in;
	private PrintWriter out;

	private void solve() {
		FlowGraph graph = new FlowDenseGraph(52);
		int edgeCount = in.readInt();
		for (int i = 0; i < edgeCount; i++) {
			int source = getIndex(in.readCharacter());
			int destination = getIndex(in.readCharacter());
			int flow = in.readInt();
			graph.addEdge(source, destination, flow);
			graph.addEdge(destination, source, flow);
		}
		out.println(getMaximalFlow(graph, 0, 25));
	}

	private int getIndex(char c) {
		if (Character.isUpperCase(c))
			return c - 'A';
		return c - 'a' + 26;
	}

	public interface Edge {
		public int getDestination();

		public int getFlow();

		public void addFlow(int flow);
	}

	public interface Graph {
		public int getVertexCount();

		public Iterable<Edge> getIncident(int source);
	}

	public interface FlowGraph extends Graph {
		public void addEdge(int source, int destination, int flow);
	}

	public interface DenseGraph extends Graph {
		public boolean hasEdge(int source, int destination);

		public int getFlow(int source, int destination);

		public void addFlow(int source, int destination, int flow);
	}

	public static class DenseEdge implements Edge, Iterator<Edge> {
		private final int source;
		private final DenseGraph graph;
		private int destination = -1;
		private int nextDestination;

		public DenseEdge(int source, DenseGraph graph) {
			this.source = source;
			this.graph = graph;
			advance();
		}

		private void advance() {
			int vertexCount = graph.getVertexCount();
			for (nextDestination = destination + 1; nextDestination < vertexCount && !graph.hasEdge(source,
					nextDestination); nextDestination++);
		}

		public int getDestination() {
			return destination;
		}

		public int getFlow() {
			return graph.getFlow(source, destination);
		}

		public void addFlow(int flow) {
			graph.addFlow(source, destination, flow);
		}

		public boolean hasNext() {
			return nextDestination != graph.getVertexCount();
		}

		public Edge next() {
			destination = nextDestination;
			advance();
			return this;
		}

		public void remove() {
			throw new UnsupportedOperationException();
		}
	}

	public static abstract class AbstractDenseGraph implements DenseGraph {
		protected final int vertexCount;

		protected AbstractDenseGraph(int vertexCount) {
			this.vertexCount = vertexCount;
		}

		public int getVertexCount() {
			return vertexCount;
		}

		public Iterable<Edge> getIncident(final int source) {
			return new Iterable<Edge>() {
				public Iterator<Edge> iterator() {
					return new DenseEdge(source, AbstractDenseGraph.this);
				}
			};
		}

		public boolean hasEdge(int source, int destination) {
			return false;
		}

		public int getFlow(int source, int destination) {
			return 0;
		}

		public void addFlow(int source, int destination, int flow) {
			throw new UnsupportedOperationException();
		}

	}

	public static class FlowDenseGraph extends AbstractDenseGraph implements FlowGraph {
		private int[][] flow;
		private int[][] currentFlow;

		protected FlowDenseGraph(int vertexCount) {
			super(vertexCount);
			flow = new int[vertexCount][vertexCount];
			currentFlow = new int[vertexCount][vertexCount];
		}

		public void addEdge(int source, int destination, int flow) {
			this.flow[source][destination] += flow;
		}

		@Override
		public boolean hasEdge(int source, int destination) {
			return currentFlow[source][destination] != 0 || flow[source][destination] != 0;
		}

		@Override
		public int getFlow(int source, int destination) {
			return flow[source][destination] + currentFlow[destination][source];
		}

		@Override
		public void addFlow(int source, int destination, int flow) {
			if (flow > getFlow(source, destination))
				throw new IllegalArgumentException("Not enough flow");
			int backFlow = Math.min(currentFlow[destination][source], flow);
			currentFlow[destination][source] -= backFlow;
			flow -= backFlow;
			this.flow[source][destination] -= flow;
			currentFlow[source][destination] += flow;
		}

	}

	public static int getMaximalFlow(FlowGraph graph, int source, int destination) {
		int totalFlow = 0;
		int currentFlow;
		boolean[] visited = new boolean[graph.getVertexCount()];
		do {
			Arrays.fill(visited, false);
			currentFlow = flowImpl(graph, source, destination, visited, Integer.MAX_VALUE);
			totalFlow += currentFlow;
		} while (currentFlow != 0);
		return totalFlow;
	}

	private static int flowImpl(FlowGraph graph, int source, int destination, boolean[] visited, int maxFlow) {
		if (source == destination)
			return maxFlow;
		if (visited[source])
			return 0;
		visited[source] = true;
		for (Edge edge : graph.getIncident(source)) {
			if (edge.getFlow() != 0) {
				int currentFlow = flowImpl(graph, edge.getDestination(), destination, visited, Math.min(maxFlow, edge.getFlow()));
				if (currentFlow != 0) {
					edge.addFlow(currentFlow);
					return currentFlow;
				}
			}
		}
		return 0;
	}

	public static void main(String[] args) {
		new MTotalF().run();
	}

	private MTotalF() {
		@SuppressWarnings({"UnusedDeclaration"})
		String id = getClass().getName().toLowerCase();
		//noinspection EmptyTryBlock
		try {
//			System.setIn(new FileInputStream(id + ".in"));
//			System.setOut(new PrintStream(new FileOutputStream(id + ".out")));
//			System.setIn(new FileInputStream("input.txt"));
//			System.setOut(new PrintStream(new FileOutputStream("output.txt")));
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
	}

	private void run() {
		//noinspection InfiniteLoopStatement
//		int testCount = in.readInt();
//		for (int i = 0; i < testCount; i++)
//		while (true)
		solve();
		exit();
	}

	@SuppressWarnings({"UnusedDeclaration"})
	private void exit() {
		out.close();
		System.exit(0);
	}

	@SuppressWarnings({"UnusedDeclaration"})
	private static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar, numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public int[] readIntArray(int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++)
				array[i] = readInt();
			return array;
		}

		public long[] readLongArray(int size) {
			long[] array = new long[size];
			for (int i = 0; i < size; i++)
				array[i] = readLong();
			return array;
		}

		public double[] readDoubleArray(int size) {
			double[] array = new double[size];
			for (int i = 0; i < size; i++)
				array[i] = readDouble();
			return array;
		}

		public String[] readStringArray(int size) {
			String[] array = new String[size];
			for (int i = 0; i < size; i++)
				array[i] = readString();
			return array;
		}

		public char[][] readTable(int rowCount, int columnCount) {
			char[][] table = new char[rowCount][columnCount];
			for (int i = 0; i < rowCount; i++) {
				for (int j = 0; j < columnCount; j++)
					table[i][j] = readCharacter();
			}
			return table;
		}

		public void readIntArrays(int[]... arrays) {
			for (int i = 0; i < arrays[0].length; i++) {
				for (int j = 0; j < arrays.length; j++)
					arrays[j][i] = readInt();
			}
		}
	}
}
